package com.moly.websocketone.configuration.webmvc;

import com.moly.websocketone.handler.ArgumentHandler;
import com.moly.websocketone.interceptor.AESInterceptor;
import com.moly.websocketone.interceptor.TestInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.Ordered;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @Description:
 * @Author: m01
 * @Date: created at  2018/11/10  17:38
 * @Modified By:
 */
@Configuration
public class WebmvcConfig implements WebMvcConfigurer {


    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("/hello");
        registry.addViewController("/error").setViewName("/hello");
        registry.setOrder(Ordered.HIGHEST_PRECEDENCE);
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        /**
         * 注册 过滤器
         */
        registry.addInterceptor(new TestInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/aes/**");
    }

    @Override
    public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> handlers) {
        /**
         *增加 返回结果 处理器
         * 用于 进一步封装 返回结果
         */

        AESInterceptor aesinterceptor = new AESInterceptor();
        handlers.add(aesinterceptor);
    }

    @Override
    public void addArgumentResolvers(List<HandlerMethodArgumentResolver> resolvers) {

        /**
         * 增加 前台参数 处理器
         * 用于 在Controller前处理 参数
         */
        ArgumentHandler argumentHandler = new ArgumentHandler();
        resolvers.add(argumentHandler);

    }
}
